﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AutoIE
{
    public class Generator
    {
        public string MyClassName = "MyProcessor";
        public string NameSapce = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace;
        private string format =
@"
using System;
namespace {0}
{{
    class {1} : BasicProcessor
    {{
        public override void Run()
        {{
            {2}
        }}
    }}
}}";
        public string Generate(string script)
        {
            return string.Format(format, NameSapce, MyClassName, script);
        }
        public string GenerateFromFile(string fileName)
        {
            StreamReader sr = new StreamReader(fileName);
            string script = sr.ReadToEnd();
            sr.Close();
            return Generate(script);
        }
        public string FullClassName
        {
            get { return NameSapce + "." + MyClassName; }
        }

        static public void Save(string code, string fileName)
        {
            StreamWriter sw = new StreamWriter(fileName);
            sw.Write(code);
            sw.Close();
        }
    }
}
